<?php
namespace App\Services;

class ResponseService
{
    CONST SUCCESS = 0;
    CONST FAIL_MESSAGE = '请求失败';
    CONST SUCCESS_MESSAGE = '请求成功';
    CONST LOGIN_SUCCESS_MESSAGE = '登录成功';

    public static function returnJson($code, $data, $cookie = [])
    {
        $return['code'] = $code;
        $return['message'] = isset($data['message']) ? $data['message'] : '请求失败';
        $return['data'] = isset($data['data']) ? $data['data'] : [];
        $return['url'] = isset($data['url']) ? $data['url'] : '';
        $resposne = response(json_encode($return))->withHeaders([
            'Content-Type' => 'application/json'
        ]);
        if($cookie) {
            $resposne->cookie($cookie['key'], $cookie['value'], $cookie['minutes']);
        }
        return $resposne;
    }
}